﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Meshomatic;
using System.IO;

namespace Reconstructor
{
    class MainController
    {
        private static MainController _instance;

        public ModelDataBuilder meshDataBuilder;
        public MeshDrawer drawer;
        public MainWindow window;

        public bool draw;

        private bool drawerSetup;

        public static MainController Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new MainController();
                }
                return _instance;
            }
        }

        public void RegisterMainVindow(MainWindow mWindow)
        {
            window = mWindow;
        }

        public static void LogToStatusBar(string message)
        {
            Instance.window.toolStripStatus.Text = message;
        }

        public MainController()
        {
            meshDataBuilder = new ModelDataBuilder();
        }

        public void LoadMeshDataFromFile(Stream stream,FileFormat format)
        {
            meshDataBuilder.LoadMesh(stream, format);
            LogToStatusBar("Mesh Loaded");
        }
        internal void LoadTexture(Stream stream)
        {
            meshDataBuilder.LoadTexture(stream);
            LogToStatusBar("Texture Loaded");
        }

        public MeshData GetMeshDataToDisplay()
        {
            return meshDataBuilder.mesh;
        }

        internal void StartDrawing()
        {
            drawer = new MeshDrawer(meshDataBuilder.mesh, meshDataBuilder.texture);
            drawer.Init(EventArgs.Empty);
            window.GLControl.Invalidate();
            draw = true;
        }
    }
}
